//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package utils

import "time"

func GetCurWeek(timeStamp int64) uint32 {
	year, week := time.UnixMilli(timeStamp).ISOWeek()
	return uint32(year*100 + week)
}

func GetLastWeek(timeStamp int64) uint32 {
	year, week := time.UnixMilli(timeStamp).Add(-7 * 24 * time.Hour).ISOWeek()
	return uint32(year*100 + week)
}

func GetCurMonth(timeStamp int64) uint32 {
	now := time.UnixMilli(timeStamp)
	year := now.Year()
	month := now.Month()
	return uint32(year*100 + int(month))
}

func GetLastMonth(timeStamp int64) uint32 {
	now := time.UnixMilli(timeStamp)
	year := now.Year()
	month := now.Month()
	if month > 1 {
		month = month - 1
	} else {
		month = time.December
		year = year - 1
	}
	return uint32(year*100 + int(month))
}

func GetCurDay(timeStamp int64) uint32 {
	now := time.UnixMilli(timeStamp)
	year := now.Year()
	month := now.Month()
	day := now.Day()
	return uint32(year*10000 + int(month)*100 + day)
}
